// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class PATIENT_RSP_Z88 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("11 PID",11)]
  	    [HL7Field(HL7Version.v24, 11, HL7Repeat.False, HL7Required.True,"PID")]
	    public PID PID {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("13 PD1",13)]
  	    [HL7Field(HL7Version.v24, 13, HL7Repeat.False, HL7Required.False,"PD1")]
	    public PD1 PD1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("17 NTE",17)]
  	    [HL7Field(HL7Version.v24, 17, HL7Repeat.True, HL7Required.False,"NTE")]
	    public NTE[] NTE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("20 ALLERGY",20)]
  	    [HL7Field(HL7Version.v24, 20, HL7Repeat.False, HL7Required.False,"ALLERGY_RSP_Z88")]
	    public ALLERGY_RSP_Z88 ALLERGY {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("31 COMMON_ORDER",31)]
  	    [HL7Field(HL7Version.v24, 31, HL7Repeat.True, HL7Required.True,"COMMON_ORDER_RSP_Z88")]
	    public COMMON_ORDER_RSP_Z88[] COMMON_ORDER {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
			PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
			NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
			ALLERGY = ProcessGroup<ALLERGY_RSP_Z88>(availableData, options, "ALLERGY");
			COMMON_ORDER = ProcessGroupArray<COMMON_ORDER_RSP_Z88>(availableData, options, "COMMON_ORDER");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isPID = availableData.StartsWith("PID", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PID", options.Version) || isPID) {
				return isPID;
			}
			bool isPD1 = availableData.StartsWith("PD1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PD1", options.Version) || isPD1) {
				return isPD1;
			}
			bool isNTE = availableData.StartsWith("NTE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NTE", options.Version) || isNTE) {
				return isNTE;
			}
			ALLERGY_RSP_Z88 testALLERGY_RSP_Z88 = new ALLERGY_RSP_Z88();
			bool grpCCALLERGY_RSP_Z88 = (testALLERGY_RSP_Z88.CanConsume(availableData, options));
			if (IsRequired("ALLERGY", options.Version) || grpCCALLERGY_RSP_Z88) {
				return grpCCALLERGY_RSP_Z88;
			}
			COMMON_ORDER_RSP_Z88 testCOMMON_ORDER_RSP_Z88 = new COMMON_ORDER_RSP_Z88();
			bool grpCCCOMMON_ORDER_RSP_Z88 = (testCOMMON_ORDER_RSP_Z88.CanConsume(availableData, options));
			if (IsRequired("COMMON_ORDER", options.Version) || grpCCCOMMON_ORDER_RSP_Z88) {
				return grpCCCOMMON_ORDER_RSP_Z88;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "PATIENT";
			}
        }

        static PATIENT_RSP_Z88() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(PATIENT_RSP_Z88));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PID != null) {
			string segmentValue = PID.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PD1 != null) {
			string segmentValue = PD1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (NTE != null && NTE.Length > 0) {
			for (int i = 0; i < NTE.Length; i++) {
				string segmentValue = NTE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (ALLERGY != null) {
			string segmentValue = ALLERGY.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (COMMON_ORDER != null && COMMON_ORDER.Length > 0) {
			for (int i = 0; i < COMMON_ORDER.Length; i++) {
				string segmentValue = COMMON_ORDER[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

